package com.briup.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.demo.bean.CmsComment;
import com.briup.demo.common.Response;
import com.briup.demo.service.CmsCommentService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(tags = "评论管理")
@RestController
@RequestMapping("/comment")
public class CmsCommentController {

	@Autowired
	private CmsCommentService commentService;
	
	@ApiOperation(value = "按照评论编号删除评论")
	@DeleteMapping("/deleteById")
	public Response<String> deleteById(String id){
		//调用业务方法
		commentService.deleteById(id);
		return Response.ok("成功删除！");
	}
	
	@ApiOperation(value = "审核评论")
	@ApiImplicitParams({
		@ApiImplicitParam(name="commentId",value = "评论编号"),
		@ApiImplicitParam(name = "state",value = "状态",
							allowableValues = "已发布,已驳回")
	})
	
	@PutMapping(value = "/updateState")
	public Response<String> updateState(String commentId,
			String state){
		boolean b = commentService.updateState(commentId, state);
		if(b) return Response.ok("操作成功！");
		else return Response.error("要更新的文章不存在！");
	}
	
	@ApiOperation(value = "显示所有评论")
	@GetMapping("/all")
	public Response<List<CmsComment>> selectAll(){
		List<CmsComment> cc = commentService.getAllComment();
		return Response.ok(cc);		
	}
}

